<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'cargo-export-form',
	'enableAjaxValidation'=>false,
)); ?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>
	
	<?php echo $form->labelEx($model['cargo'],'shipper')?>
	<hr />
	<section>
	<div class="row">
		<span class="column">
		<?php echo CHtml::radioButton('shipper',empty($model['cargo_export']->exporter));?>
		</span>
		<span class="column">
		<?php echo $form->dropDownList($model['shipper'],'cname',array($model['shipper']->cname=>$model['shipper']->cname),array('style'=>'width:420px;')); ?>
		<br />
		<?php echo $form->dropDownList($model['shipper'],'address',CHtml::listData($model['shipper']->address,'address','address'),array('style'=>'width:420px;')); ?>
		</span>
	</div>
	
	<div class="row clear">
		<span class="column">
		<?php echo CHtml::radioButton('shipper',!empty($model['cargo_export']->exporter),array('value'=>'user-defined'));?>
		</span>
		<span class="column">
		<?php echo $form->textArea($model['cargo_export'],'exporter',array('disabled'=>'disabled','cols'=>50)); ?>
		<?php echo $form->error($model['cargo_export'],'exporter'); ?>
		</span>
	</div>
	</section>
	<?php echo $form->labelEx($model['cargo'],'consignee',array('class'=>'clear'))?>
	<hr />
	<section>
	<div class="row clear">
		<span class="column">
			<?php echo CHtml::radioButton('consignee',empty($model['cargo_export']->consignee));?>
		</span>
		<span class="column">
		<?php echo $form->dropDownList($model['consignee'],'cname',array($model['consignee']->cname=>$model['consignee']->cname),array('style'=>'width:420px;')); ?>
		<br />
		<?php echo $form->dropDownList($model['consignee'],'address',CHtml::listData($model['consignee']->address,'address','address'),array('style'=>'width:420px;')); ?>
		</span>
	</div>
	
	<div class="row clear">
		<span class="column">
			<?php echo CHtml::radioButton('consignee',!empty($model['cargo_export']->consignee),array('value'=>'user-defined'));?>
		</span>
		<span class="column">
		<?php echo $form->textArea($model['cargo_export'],'consignee',array('disabled'=>'disabled','cols'=>50)); ?>
		<?php echo $form->error($model['cargo_export'],'consignee'); ?>
		</span>
	</div>
	</section>
	<?php echo CHtml::label("Information","export",array('class'=>'clear'));?>
	<hr />
	
	<div class="row">
		<?php echo $form->labelEx($model['cargo'],'amt'); ?>
		<?php echo $form->textField($model['cargo'],'amt',array('size'=>52)); ?>
		<?php echo $form->error($model['cargo'],'amt'); ?>
	</div>
	
	<div class="row">
		<?php echo $form->labelEx($model['cargo_export'],'exporter_ref'); ?>
		<?php echo $form->dropDownList($model['cargo_export'],'exporter_ref',$model['cargo']->invoice_select,array('style'=>'width:450px;')); ?>
		<?php echo $form->error($model['cargo_export'],'exporter_ref'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model['cargo_export'],'remark'); ?>
		<?php echo $form->textArea($model['cargo_export'],'remark',array('cols'=>53)); ?>
		<?php echo $form->error($model['cargo_export'],'remark'); ?>
	</div>



	<div class="row buttons">
		<?php 
        	$this->widget('zii.widgets.jui.CJuiButton',array(
        		'name'=>'submit',
        		'caption'=>($model['cargo_export']->isNewRecord)?'Save':'Update',
        		'value'=>"submit",
        	)); 
        ?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->
<?php
$cs = Yii::app()->getClientScript();
$exportUrl = CHtml::normalizeUrl(array('export_information/view','id'=>$model['export_info']->id,'packing_id'=>$model['cargo']->packing_id));
$script =<<<EOD
$('input#shipper,input#consignee').change(function(){
	var container = $(this).parents('section'); 
	$(container).find('textarea,select').attr('disabled','disabled');
	var selected = $(this).parents('.row'); 
	$(selected).find('textarea,select').removeAttr('disabled');	
});
$.cargo_export_form_afterSubmit = {
	afterSubmit:function(data){window.location = "$exportUrl";}
};
$('#cargo-export-form [type=submit]').click(function(){	
	var form = $.extend($.simplelogform,$.cargo_export_form_afterSubmit);
	form.Submit($('#cargo-export-form'));
	return false;
});
$('input#shipper,input#consignee').change();
EOD;
$cs->registerScript('cargo#view',$script); 
?>